package cn.com.dhcc.ddi.task.dao;

import cn.com.dhcc.app.core.dao.BaseDao;
import cn.com.dhcc.app.core.exception.DaoException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.ddi.task.vo.TaskFilter;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

/**
 *
 * @日期：2017/5/8 13:31
 * @作者：张洪涛
 * @版权所有：东华软件
 * @版本：1.0
 */
@Repository
public class TaskFilterDao extends BaseDao {
    private static Logger logger = Log.getLogger(Log.LOGTYPE.DDI);
    /**
     * 增加任务文件过滤条件
     * @param vo
     * @return
     * @throws DaoException
     */
    public int insertTaskFilter(TaskFilter vo) throws DaoException {
        String msg = "";
        try {
            return getDao().insertModule("新增",vo);
        } catch (DaoException e) {
            msg = "新增任务文件过滤条件失败";
            logger.error(msg,e);
            throw new DaoException(msg,e);
        }
    }

    /**
     *修改任务文件过滤条件
     * @param vo
     * @return
     * @throws DaoException
     */
    public int updateTaskFilter(TaskFilter vo) throws DaoException {
        String msg = "";
        try {
            return getDao().updateModuleByIdExecuteNull("修改",vo);
        } catch (DaoException e) {
            msg = "修改任务文件过滤条件失败";
            logger.error(msg,e);
            throw new DaoException(msg,e);
        }
    }

    /**
     * 查询任务文件过滤条件
     * @param taskId 任务id
     * @return
     * @throws DaoException
     */
    public TaskFilter getTaskFilterByTaskId(String taskId) throws DaoException {
        String msg = "";
        String sql = " select * from "+SI_TABLE("t_ddi_task_filter") + " where task_id=?";
        try {
            return getDao().getModule("查询",sql,TaskFilter.class,new Object[]{taskId});
        } catch (DaoException e) {
            msg = "查询任务文件过滤条件失败";
            logger.error(msg,e);
            throw new DaoException(msg,e);
        }
    }

    /**
     * 删除任务文件过滤条件
     * @param taskId 任务id
     * @return
     * @throws DaoException
     */
    public int deleteTaskFilterByTaskId(String taskId) throws DaoException {
        String msg = "";
        String sql = "delete from "+SI_TABLE("t_ddi_task_filter") + " where task_id=?";
        try {
            return getDao().delete("",sql,new Object[]{taskId});
        } catch (DaoException e) {
            msg = "删除任务文件过滤条件失败";
            logger.error(msg,e);
            throw new DaoException(msg,e);
        }
    }
}
